/*
 * Filename:    EvaluationIllegalController.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014-11-10
 */
package com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.paic.mhis.common.util.HttpProcessUtil;
import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.biz.service.EvaluationIllegalService;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.constants.EvaluationOrgConstants;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.dto.EvalMarkUserComfirmDTO;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.dto.EvaluationPointCutInfo;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.dto.IntegrityEvalDTO;
import com.paic.pafa.appclient.annotation.BizServicesProxy;

/**
 * 该控制器主要是对定点机构诚信考评
 * 
 * @author EX-LUORONG001
 * 
 */
@Controller
@RequestMapping("/evaluationIllegal/")
public class EvaluationIllegalController {

	@BizServicesProxy(beanName = "evaluationIllegalServiceImpl")
	private EvaluationIllegalService evaluationIllegalService;

	/**
	 * 根据id加载对应的诚信单位考评详情
	 * 
	 * @param vo
	 * @param request
	 * @return
	 */
	@RequestMapping("loadIntgrityEvalInfo.do")
	@ResponseBody
	public Map<String, Object> loadIntgrityEvalInfo(@ModelAttribute IntegrityEvalDTO intgrityEvalDTO,
			HttpServletRequest request) {

		Map<String, Object> result = new HashMap<String, Object>();
		intgrityEvalDTO.setEvaluationType(EvaluationOrgConstants.EvaluationType_Org);
		Map<String, Object> intgrityEvalInfo = this.evaluationIllegalService.getIntgrityEvalInfo(intgrityEvalDTO);
		result.put(EvaluationOrgConstants.STATE_KEY, EvaluationOrgConstants.FLAG_TURE);
		result.put(EvaluationOrgConstants.SUCCESS_RESULT_KEY, intgrityEvalInfo);
		return result;
	}
	
	
	
	
	@RequestMapping("queryPointValue.do")
	@ResponseBody
	public Map<String, Object> queryPointValue(HttpServletRequest request) {

		String orgCode=request.getParameter("orgCode");
		String targetType=request.getParameter("targetType");
		String standardScoreId=request.getParameter("standardScoreId");
		
		List<EvaluationPointCutInfo> list=this.evaluationIllegalService.queryPointValue(orgCode, standardScoreId, targetType);
		
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("flag",true);
		result.put("list", list);
		
		return result;
	}
	
	
	

	/**
	 * 根据id加载对应的诚信类别考评详情
	 * 
	 * @param vo
	 * @param request
	 * @return
	 */
	@RequestMapping("loadIntgrityEvalTypeInfo.do")
	@ResponseBody
	public Map<String, Object> loadIntgrityEvalTypeInfo(@ModelAttribute IntegrityEvalDTO intgrityEvalDTO,
			HttpServletRequest request) {

		Map<String, Object> result = new HashMap<String, Object>();
		Map<String, Object> list = this.evaluationIllegalService.getIntgrityEvalTypeInfo(intgrityEvalDTO);
		result.put(EvaluationOrgConstants.STATE_KEY, EvaluationOrgConstants.FLAG_TURE);
		result.put(EvaluationOrgConstants.SUCCESS_RESULT_KEY, list);
		return result;
	}

	/**
	 * 根据id加载对应的诚信考评详情
	 * 
	 * @param vo
	 * @param request
	 * @return
	 */
	@RequestMapping("loadIntgrityEvalDetailInfo.do")
	@ResponseBody
	public Map<String, Object> loadIntgrityEvalDetailInfo(@ModelAttribute EvalMarkUserComfirmDTO eComfirmDTO,
			HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			String ruleId = eComfirmDTO.getEvaluRuleId();
			String evalChildId = eComfirmDTO.getIntgrityEvalChildId();
			Map<String, Object> list = this.evaluationIllegalService.getIntgrityEvalDetail(ruleId, evalChildId,EvaluationOrgConstants.TARGETTYPE_01);
			result.put(EvaluationOrgConstants.STATE_KEY, EvaluationOrgConstants.FLAG_TURE);
			result.put(EvaluationOrgConstants.SUCCESS_RESULT_KEY, list);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		return result;
	}

	/**
	 * 根据诚信考评类别保存或暂存其扣分信息
	 * 
	 * @param vo
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "saveIntgrityEvalInfo.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> addIntgrityEvalInfo(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");

			String str = HttpProcessUtil.readRequestBody(request);
			JSONObject transferJson = JSON.parseObject(str);

			EvalMarkUserComfirmDTO comfirmDTO = JSONObject.toJavaObject(transferJson, EvalMarkUserComfirmDTO.class);

			result = this.evaluationIllegalService.saveEvaluationInfoConfirm(comfirmDTO, user);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		return result;
	}
}
